#ifndef _D3DMANAGER_H_
#define _D3DMANAGER_H_

#include <string>
#include <d3d9.h>

class D3DManager
{
public:
	D3DManager(void);
	~D3DManager(void);
	static D3DManager& getInstance()
	{
		static D3DManager instance;
		return instance;
	}

	HRESULT Init(HWND hwnd);

	void shutdown(void);

	void beginRender(void);

	void endRender(void);

	IDirect3DSurface9* getSurfaceFromBitmap(std::string filename);

	IDirect3DSurface9* getBackBuffer(void);

	inline LPDIRECT3DDEVICE9 getD3DDevice(void) { return pd3dDevice; }

	void blitToSurface(IDirect3DSurface9* srcSurface,const RECT *srcRect,const RECT *destRect);

	LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size, DWORD usage);
private:
	// the Direct3D object
	LPDIRECT3D9 pD3D;

	LPDIRECT3DDEVICE9 pd3dDevice;

	int screen_width;
	int screen_height;
};
namespace d3d
{
	const D3DXCOLOR      WHITE( D3DCOLOR_XRGB(255, 255, 255) );
	const D3DXCOLOR      BLACK( D3DCOLOR_XRGB(  0,   0,   0) );
	const D3DXCOLOR        RED( D3DCOLOR_XRGB(255,   0,   0) );
	const D3DXCOLOR      GREEN( D3DCOLOR_XRGB(  0, 255,   0) );
	const D3DXCOLOR       BLUE( D3DCOLOR_XRGB(  0,   0, 255) );
	const D3DXCOLOR     YELLOW( D3DCOLOR_XRGB(255, 255,   0) );
	const D3DXCOLOR       CYAN( D3DCOLOR_XRGB(  0, 255, 255) );
	const D3DXCOLOR    MAGENTA( D3DCOLOR_XRGB(255,   0, 255) );

	const D3DXCOLOR BEACH_SAND( D3DCOLOR_XRGB(255, 249, 157) );
	const D3DXCOLOR DESERT_SAND( D3DCOLOR_XRGB(250, 205, 135) );

	const D3DXCOLOR LIGHTGREEN( D3DCOLOR_XRGB( 60, 184, 120) );
	const D3DXCOLOR  PUREGREEN( D3DCOLOR_XRGB(  0, 166,  81) );
	const D3DXCOLOR  DARKGREEN( D3DCOLOR_XRGB(  0, 114,  54) );

	const D3DXCOLOR LIGHT_YELLOW_GREEN( D3DCOLOR_XRGB(124, 197, 118) );
	const D3DXCOLOR  PURE_YELLOW_GREEN( D3DCOLOR_XRGB( 57, 181,  74) );
	const D3DXCOLOR  DARK_YELLOW_GREEN( D3DCOLOR_XRGB( 25, 123,  48) );

	const D3DXCOLOR LIGHTBROWN(D3DCOLOR_XRGB(198, 156, 109));
	const D3DXCOLOR DARKBROWN( D3DCOLOR_XRGB(115, 100,  87));

	float Lerp(float a, float b, float t);
}
#endif